package org.example.helloworld.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.helloworld.entity.Water;
import org.springframework.beans.factory.annotation.Autowired;
import org.example.helloworld.service.WaterService;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/water")
public class WaterController {

    @Autowired
    private WaterService waterService;


    @GetMapping
    public List<Water> getAllRates() {
        return waterService.list();
    }

    @GetMapping("/{id}")
    public Water getRateById(@PathVariable String id) {
        return waterService.getById(id);
    }

    @PostMapping
    public boolean addRate(@RequestBody Water rate) {
        return waterService.save(rate);
    }

    @PutMapping
    public boolean updateRate(@RequestBody Water rate) {
        return waterService.updateById(rate);
    }

    @DeleteMapping("/{id}")
    public boolean deleteRate(@PathVariable String id) {
        return waterService.removeById(id);
    }

    @GetMapping("/search")
    public List<Water> searchRates(@RequestParam String step) {
        QueryWrapper<Water> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("step", step);
        return waterService.list(queryWrapper);
    }

}
